﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DerptelligenceSite.Areas.Marein.Models.Blog;

namespace DerptelligenceSite.Areas.Marein.Controllers
{
    public class BlogController : Controller
    {
		public ActionResult Home()
		{
			BlogTopic page_topic = BlogDatabase.GetTopicByShortTitle( "home" );

			ViewData["html_title"] = "Home";

			ViewData["page_topic"] = page_topic;
			ViewData["page_title"] = page_topic.title;
			ViewData["page_info"] = page_topic.info;

			ViewData["entries"] = BlogDatabase.GetEntries();

			return View( "Entries" );
		}

		public ActionResult Topic( String id )
		{
			if ( id == "home" ) { return RedirectToAction( "Home" ); }

			BlogTopic page_topic = BlogDatabase.GetTopicByShortTitle( id );

			ViewData["html_title"] = "Topic: " + page_topic.title;

			ViewData["page_topic"] = page_topic;
			ViewData["page_title"] = "Entries from " + page_topic.title;
			ViewData["page_info"] = page_topic.info;

			ViewData["entries"] = BlogDatabase.GetEntriesByTopic( page_topic );

			return View( "Entries" );
		}

		public ActionResult Entry( UInt32 id )
		{
			if ( id == null )
			{
				RedirectToAction( "Home" );
			}

			BlogEntry entry = BlogDatabase.GetEntryByID( id );
			BlogTopic page_topic = entry.topic;

			ViewData["html_title"] = "Entry: " + entry.title;

			ViewData["page_topic"] = page_topic;
			ViewData["page_title"] = "Entry from " + page_topic.title;
			ViewData["page_info"] = page_topic.info;

			ViewData["entries"] = BlogDatabase.GetEntriesByTopic( page_topic );
			ViewData["comments"] = BlogDatabase.GetCommentsByEntryID( id );

			return View( "Entries" );
		}

		public ActionResult Tag( String id )
		{
			if ( String.IsNullOrEmpty( id ) )
			{
				RedirectToAction( "Home" );
			}

			ViewData["tag"] = id;

			return View( "Tag" );
		}

		public ActionResult Date( String id )
		{
			if ( String.IsNullOrEmpty( id ) )
			{
				RedirectToAction( "Home" );
			}

			ViewData["date"] = id;

			return View( "Date" );
		}

		public ActionResult Search( String id )
		{
			if ( String.IsNullOrEmpty( id ) )
			{
				RedirectToAction( "Home" );
			}

			return View( "Search" );
		}
    }
}
